package com.guoguo.service.impl;

import com.github.pagehelper.PageHelper;
import com.guoguo.api.UsersController;
import com.guoguo.base.PageBean;
import com.guoguo.base.PaginationContext;
import com.guoguo.entity.vo.BuyAlbumVO;
import com.guoguo.mapper.UsersMapper;
import com.guoguo.service.BuyAlbumService;
import com.guoguo.utils.AliOssUtils;
import com.guoguo.utils.aliOss.AliOssImageConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/17.
 */
@Service
public class BuyAlbumServiceImpl implements BuyAlbumService {
    private final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UsersController.class);
    //获取已购买的专辑详情
    @Autowired
    private UsersMapper userMapper;


    public PageBean<BuyAlbumVO> UserBuyAlbum(String userId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<BuyAlbumVO> buyAlbumVOList = userMapper.UserBuyAlbum(userId);

        //样式集
//        List<AliOssImageConfig> aliOssImageConfigs = new ArrayList<>();
//        AliOssImageConfig aliOssImageConfig = new AliOssImageConfig("test");

//        aliOssImageConfigs.add(aliOssImageConfig);
        for (BuyAlbumVO buyAlbumVO : buyAlbumVOList) {
            if (buyAlbumVO != null) {
                List<String> imageUrlList = new ArrayList<>();
                imageUrlList.add(buyAlbumVO.getModelIcon());
                imageUrlList.add(buyAlbumVO.getCoverUrl());
                Map<String, String> fileUrlMap = AliOssUtils.getImageUrlList(imageUrlList);//, aliOssImageConfigs);

                buyAlbumVO.setModelIcon(fileUrlMap.get(buyAlbumVO.getModelIcon()));
                buyAlbumVO.setCoverUrl(fileUrlMap.get(buyAlbumVO.getCoverUrl()));
            }
        }
        return new PageBean<BuyAlbumVO>(buyAlbumVOList);

    }


}
